<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link th:href="@{/ruoyi/css/import/common.css}" rel="stylesheet"/>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form id="fileUpload" method="post" class="form-horizontal">
			<div class="form-group">
				<label class="col-sm-2 control-label">格式要求</label>

				<!--<div class="col-sm-10">
                    <p class="form-control-static"> IMEI码, 型号, 尺寸, 分辨率, 批次号, 颜色, 生产厂家, 生产日期, 所属公司编码</p>
                </div>-->
				<!--<div class="col-sm-1">
					<a th:href="@{/pub/mainControlPanel/exportTemplet}" class="btn btn-white"
					   type="button">下载导入模板</a>
				</div>-->
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">数据文件</label>

				<div class="col-sm-8 report-file">
					<span>上传文件...</span>
					<input th:type="file" class="form-control file-prew" name="file"
						   onchange="document.getElementById('fileName').value=this.value;document.getElementById('submit_btn').disabled=false"
						   accept="application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet">
				</div>
				<div class="col-sm-4">
					<input type="text" id="fileName" readonly="readonly"/>
				</div>
				<div class="col-sm-2">*仅支持Excel文件</div>
			</div>
			<div class="hr-line-dashed"></div>
			<div class="form-group">
				<div class="col-sm-4 col-sm-offset-2">
					<button class="btn btn-primary" type="submit" id="submit_btn"disabled="disabled" >导入</button>
					<!--<a th:href="@{/pub/mainControlPanel}" id="cancel_btn" class="btn btn-white"
					   type="button">取消</a>-->
					<!--<a class="btn btn-white" onclick="closeFrame()" type="button">关闭</a>-->
				</div>
			</div>
		</form>
	<div id="loading"></div>
</div>
<div th:include="include::footer"></div>
<script>
    $(document).ready(function () {
        $("#submit_btn").click(function (event) {
            event.preventDefault();
            var r = confirm("确认导入吗？");
            if(r) {
                var form = $('#fileUpload')[0];
                var data = new FormData(form);

                $("#submit_btn").prop("disabled", true);

                $.ajax({
                    type: "POST",
                    enctype: 'multipart/form-data',
                    url: "/shop/goods/import",
                    data: data,
                    beforeSend: function (xhr) {
                        /*xhr.setRequestHeader(
                            $("meta[name='_csrf_header']").attr("content"), $("meta[name='_csrf']").attr("content")
                        );*/
                        $("#loading").html("<img style='padding-left: 40%;' src='/img/loading.gif' />");
                    },
                    processData: false,
                    contentType: false,
                    cache: false,
                    timeout: 600000,
                    success: function (result) {
                       /* $("#loading").empty();
                        console.log(response);
                        if (response.code=='0') {
                            $("#submit_btn").prop("disabled", false);
                            $.modal.msgSuccess('导入成功');
                        } else {
                            $("#submit_btn").prop("disabled", false);
                            $.modal.msgError(response.msg);
                        }*/
                        if (window.parent.$("#bootstrap-table").length > 0) {
                            $("#submit_btn").prop("disabled", false);
                            $.modal.close();
                            window.parent.$.modal.msgSuccess(result.msg);
                            window.parent.$.table.refresh();
                        } else if (window.parent.$("#bootstrap-tree-table").length > 0) {
                            $("#submit_btn").prop("disabled", false);
                            $.modal.close();
                            window.parent.$.modal.msgSuccess(result.msg);
                            window.parent.$.treeTable.refresh();
                        } else {
                            $("#submit_btn").prop("disabled", false);
                            $.modal.msgReload("保存成功,正在刷新数据请稍后……", modal_status.SUCCESS);
                        }

                    },
                    error: function (e) {
                        toastr.error('导入失败');
                        $("#submit_btn").prop("disabled", false);
                    }
                });
            }
        });

    });
</script>
</body>
</html>
